<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>入住登记</title>
	<#include "/common/resource.ftl">
	<link rel="stylesheet" href="${params.contextPath}/static/plug/layui/css/layui.css">
	<style>
		.layui-form select {display:none !important;}
	</style>
	<script>
		$(function () {
			$.ajaxRequest({
				url: '${params.contextPath}/web/room/listAll',
				data: {},
				success: function (data) {
					if (!data.success) {
						$.message(data.message);
						return;
					}
					var record = data.data;
					console.log(record);
					var roomStr = "<option value=''>请选择</option>";
					for (var i = 0; i < record.length; i++) {
						roomStr += "<option value='" + record[i].id + "'>"+ record[i].roomNum +"</option>";
					}
					$("#bedNum").empty();
					$("#roomId").append(roomStr);
					layui.form.render();
				}
			});

			$(".ajax-form").unbind().submit(function () {
				try {
					var form = $(this);
					if (!form.valid()) {
						$.message("验证不通过，无法提交表单");
						return false;
					}

					form.formSubmit({
						callBack:function (data) {
							<#if (params.tag)??>
							history.go(-1);
							</#if>
						}
					});
				} catch (e) {
					console.log("表单提交错误：" + e);
				}
				return false;
			});
		});
	</script>
    <style>
        .layui-form-label{width:95px;}
        .layui-input-block{margin-left:125px;}
    </style>
</head>
<body>
	<div class="ui-form">
		<form class="layui-form ajax-form" action="${params.contextPath}/web/elder/checkIn" method="post">
			<input type="hidden" name="id" value="${params.id}" />
			<div class="layui-form-item">
				<label class="layui-form-label">房间号<span class="ui-request">*</span></label>
				<div class="layui-input-block">
					<select lay-filter="roomId" id="roomId" name="roomId" class="layui-input {required:true}">

					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">床位<span class="ui-request">*</span></label>
				<div class="layui-input-block">
					<select  id="bedNum" name="bedNum" class="layui-input {required:true}">

					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">入院号<span class="ui-request">*</span></label>
				<div class="layui-input-block">
					<input type="text" name="code" placeholder="请输入入院号" class="layui-input {required:true}"/>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="submit" value="入住" class="layui-btn" />
				</div>
			</div>
		</form>
	</div>
</body>
<script src="${params.contextPath}/static/plug/layui/layui.all.js"></script>
<script>

	layui.use(['element','form'], function() {
		var form = layui.form;
		form.on('select(roomId)', function (data) {
			$.ajaxRequest({
				url: '${params.contextPath}/web/bed/bedList',
				data: {roomId: $("[name='roomId']").val()},
				success: function (data) {
					if (!data.success) {
						$.message(data.message);
						return;
					}
					var record = data.data;
					console.log(record)
					var bedStr = "<option value=''>请选择</option>";
					for (var i = 0; i < record.length; i++) {
						bedStr += "<option value='" + record[i].num + "'>" + record[i].num + "</option>";
					}
					$("#bedNum").empty();
					$("#bedNum").append(bedStr);
					layui.form.render();
				}
			});
		});
	});
</script>
</html>
